<template>
  <div class="comment-box f-c">
    <el-tabs v-model="activeName">
      <el-tab-pane label="会议纪要" name="Sign" />
    </el-tabs>
    <div style="flex-grow: 1;overflow: auto;overflow-x:hidden;padding-right: 500px">
      <SubmitForm
        :rule-form="ruleForm"
        :rules="rules"
        :form-list="formList"
        :show-close="false"
        @change="handleFormChange"
        @save="onSave"
      />
    </div>
  </div>
</template>

<script>
import {getName, Investor, MeetingType, PaperType} from '@/dict'
import { http } from '@/api'

export default {
  name: 'After',
  props: {
    currentDetail: Object
  },
  data() {
    return {
      activeName: 'Sign',
      ruleForm: {
      },
      rules: {
        projectName: [{ required: true, message: '不能为空' }]
      },
      formList: [
        {
          name: 'title',
          label: '纸张',
          colSpan: 24
        },
        {
          key: 'paper',
          name: 'select',
          label: '纸张',
          options: PaperType,
          colSpan: 12
        },
        {
          key: 'pages',
          name: 'input',
          type: 'number',
          label: '页数',
          colSpan: 12
        },
          {
              key: 'copies',
              name: 'input',
              type: 'number',
              label: '份数',
              colSpan: 12
          },
        {
          key: 'savingCapital',
          name: 'input',
          type: 'number',
          label: '节约资金（元）',
          colSpan: 12
        },
        {
          name: 'title',
          label: '会议纪要编制',
          colSpan: 24
        },
        {
          key: 'meetingName',
          name: 'input',
          label: '会议名称',
          colSpan: 12
        },
        {
          key: 'meetingStartTime',
          name: 'datetime',
          valueFormat: 'yyyy-MM-dd hh:mm:ss',
          dateType: 'datetime',
          label: '会议开始时间',
          colSpan: 24
        },
        {
          key: 'meetingContent',
          name: 'richedit',
          label: '会议纪要',
          colSpan: 24
        },
        {
          key: 'remark',
          name: 'input',
          type: 'textarea',
          label: '备注',
          colSpan: 24
        },
        {
          name: 'title3',
          label: '附件资料',
          colSpan: 24
        },
        {
          key: 'file',
          name: 'files',
          multiple: true,
          defaultValue: [],
          label: ''
        },
        {
          name: 'title4',
          label: '会议照片',
          colSpan: 24
        },
        {
          key: 'imgs',
          name: 'files',
          multiple: true,
          defaultValue: [],
          label: ''
        }
      ]
    }
  },
  created() {
      console.log('d----dasda')
    this.ruleForm = this.getForm()
      console.log('-dasda')
      http.project_center.read({ id: this.currentDetail.id }).then(res => {
          this.ruleForm.paper = res.data.paper
          this.ruleForm.pages = res.data.pages
          this.ruleForm.copies = res.data.copies
          this.ruleForm.savingCapital = res.data.savingCapital
          this.ruleForm.meetingName = res.data.meetingName == null ? res.data.projectName : res.data.meetingName
          this.ruleForm.meetingStartTime = res.data.meetingStartTime
          this.ruleForm.meetingContent = res.data.meetingContent
      })
  },
  methods: {
      handleFormChange({ key, val}) {
          if (key === 'paper' || key === 'pages') {
              this.getCapital()
          }
      },
      getCapital() {
          const { paper, pages,copies } = this.ruleForm
          if (pages && paper && copies) {
              http.admin_project_center.getSavingCapital({
                  paper,
                  pages,
                  copies
              }).then(res => {
                  console.log(res)
                  this.ruleForm.savingCapital = res.data
              })
          }
      },
    getForm() {
      const form = {
        file: [],
        imgs: []
      }
      this.formList.forEach(el => {
        if (el.key) {
          form[el.key] = el.defaultValue || ''
        }
      })
      return form
    },
    onSave() {
      http.meeting_record.create({
        id: this.currentDetail.id,
        ...this.ruleForm
      }).then(res => {
        this.$message.success(res.msg)
        // this.onPageBack()
        this.$emit("success")

      })
    }
  }
}
</script>
<style>
.comment-box {
    overflow: hidden;
}
</style>

